home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / plugins / content / pagebreak.php < prev    next >
PHP Script  |  2008-07-06  |  6KB  |  284 lines

  1. <?php
  2. /**
  3. * @version        $Id: pagebreak.php 10498 2008-07-04 00:05:36Z ian $
  4. * @package        Joomla
  5. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license        GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. $mainframe->registerEvent( 'onPrepareContent', 'plgContentPagebreak' );
  18.  
  19. /**
  20. * Page break plugin
  21. *
  22. * <b>Usage:</b>
  23. * <code><hr class="system-pagebreak" /></code>
  24. * <code><hr class="system-pagebreak" title="The page title" /></code>
  25. * or
  26. * <code><hr class="system-pagebreak" alt="The first page" /></code>
  27. * or
  28. * <code><hr class="system-pagebreak" title="The page title" alt="The first page" /></code>
  29. * or
  30. * <code><hr class="system-pagebreak" alt="The first page" title="The page title" /></code>
  31. *
  32. */
  33. function plgContentPagebreak( &$row, &$params, $page=0 )
  34. {
  35.     // expression to search for
  36.     $regex = '#<hr(.*)class=\"system-pagebreak\"(.*)\/>#iU';
  37.  
  38.     // Get Plugin info
  39.     $plugin            =& JPluginHelper::getPlugin('content', 'pagebreak');
  40.     $pluginParams    = new JParameter( $plugin->params );
  41.  
  42.     $print   = JRequest::getBool('print');
  43.     $showall = JRequest::getBool('showall');
  44.  
  45.     if (!$pluginParams->get('enabled', 1)) {
  46.         $print = true;
  47.     }
  48.  
  49.     if ($print) {
  50.         $row->text = preg_replace( $regex, '<BR/>', $row->text );
  51.         return true;
  52.     }
  53.  
  54.     //simple performance check to determine whether bot should process further
  55.     if ( JString::strpos( $row->text, 'class="system-pagebreak' ) === false ) {
  56.         return true;
  57.     }
  58.  
  59.     $db        =& JFactory::getDBO();
  60.     $full     = JRequest::getBool('fullview');
  61.  
  62.     if(!$page) {
  63.         $page = 0;
  64.     }
  65.  
  66.  
  67.     // check whether plugin has been unpublished
  68.     if (!JPluginHelper::isEnabled('content', 'pagebreak') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $full) {
  69.         $row->text = preg_replace( $regex, '', $row->text );
  70.         return;
  71.     }
  72.  
  73.     // find all instances of plugin and put in $matches
  74.     $matches = array();
  75.     preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
  76.  
  77.     if (($showall && $pluginParams->get('showall', 1) ))
  78.     {
  79.         $hasToc = $pluginParams->get( 'multipage_toc', 1 );
  80.         if ( $hasToc ) {
  81.             // display TOC
  82.             $page = 1;
  83.             plgContentCreateTOC( $row, $matches, $page );
  84.         } else {
  85.             $row->toc = '';
  86.         }
  87.         $row->text = preg_replace( $regex, '<BR/>', $row->text );
  88.         return true;
  89.     }
  90.  
  91.     // split the text around the plugin
  92.     $text = preg_split( $regex, $row->text );
  93.  
  94.     // count the number of pages
  95.     $n = count( $text );
  96.  
  97.     // we have found at least one plugin, therefore at least 2 pages
  98.     if ($n > 1)
  99.     {
  100.         // Get plugin parameters
  101.         $pluginParams = new JParameter( $plugin->params );
  102.         $title    = $pluginParams->get( 'title', 1 );
  103.         $hasToc = $pluginParams->get( 'multipage_toc', 1 );
  104.  
  105.         // adds heading or title to <site> Title
  106.         if ( $title )
  107.         {
  108.             if ( $page ) {
  109.                 $page_text = $page + 1;
  110.                 if ( $page && @$matches[$page-1][2] )
  111.                 {
  112.                     $attrs = JUtility::parseAttributes($matches[$page-1][1]);
  113.  
  114.                     if ( @$attrs['title'] ) {
  115.                         $row->page_title = $attrs['title'];
  116.                     }
  117.                 }
  118.             }
  119.         }
  120.  
  121.         // reset the text, we already hold it in the $text array
  122.         $row->text = '';
  123.  
  124.         // display TOC
  125.         if ( $hasToc ) {
  126.             plgContentCreateTOC( $row, $matches, $page );
  127.         } else {
  128.             $row->toc = '';
  129.         }
  130.  
  131.         // traditional mos page navigation
  132.         jimport('joomla.html.pagination');
  133.         $pageNav = new JPagination( $n, $page, 1 );
  134.  
  135.         // page counter
  136.         $row->text .= '<div class="pagenavcounter">';
  137.         $row->text .= $pageNav->getPagesCounter();
  138.         $row->text .= '</div>';
  139.  
  140.         // page text
  141.         $text[$page] = str_replace("<hr id=\"\"system-readmore\"\" />", "", $text[$page]);
  142.         $row->text .= $text[$page];
  143.  
  144.         $row->text .= '<br />';
  145.         $row->text .= '<div class="pagenavbar">';
  146.  
  147.         // adds navigation between pages to bottom of text
  148.         if ( $hasToc ) {
  149.             plgContentCreateNavigation( $row, $page, $n );
  150.         }
  151.  
  152.         // page links shown at bottom of page if TOC disabled
  153.         if (!$hasToc) {
  154.             $row->text .= $pageNav->getPagesLinks();
  155.         }
  156.  
  157.         $row->text .= '</div><br />';
  158.     }
  159.  
  160.     return true;
  161. }
  162.  
  163. function plgContentCreateTOC( &$row, &$matches, &$page )
  164. {
  165.  
  166.     $heading = $row->title;
  167.  
  168.     // TOC Header
  169.     $row->toc = '
  170.     <table cellpadding="0" cellspacing="0" class="contenttoc">
  171.     <tr>
  172.         <th>'
  173.         . JText::_( 'Article Index' ) .
  174.         '</th>
  175.     </tr>
  176.     ';
  177.  
  178.     // TOC First Page link
  179.     $row->toc .= '
  180.     <tr>
  181.         <td>
  182.         <a href="'. JRoute::_( '&showall=&limitstart=') .'" class="toclink">'
  183.         . $heading .
  184.         '</a>
  185.         </td>
  186.     </tr>
  187.     ';
  188.  
  189.     $i = 2;
  190.  
  191.     foreach ( $matches as $bot )
  192.     {
  193.         $link = JRoute::_( '&showall=&limitstart='. ($i-1) );
  194.  
  195.  
  196.         if ( @$bot[0] )
  197.         {
  198.             $attrs2 = JUtility::parseAttributes($bot[0]);
  199.  
  200.             if ( @$attrs2['alt'] )
  201.             {
  202.                 $title    = stripslashes( $attrs2['alt'] );
  203.             }
  204.             elseif ( @$attrs2['title'] )
  205.             {
  206.                 $title    = stripslashes( $attrs2['title'] );
  207.             }
  208.             else
  209.             {
  210.                 $title    = JText::sprintf( 'Page #', $i );
  211.             }
  212.         }
  213.         else
  214.         {
  215.             $title    = JText::sprintf( 'Page #', $i );
  216.         }
  217.  
  218.         $row->toc .= '
  219.             <tr>
  220.                 <td>
  221.                 <a href="'. $link .'" class="toclink">'
  222.                 . $title .
  223.                 '</a>
  224.                 </td>
  225.             </tr>
  226.             ';
  227.         $i++;
  228.     }
  229.  
  230.     // Get Plugin info
  231.     $plugin =& JPluginHelper::getPlugin('content', 'pagebreak');
  232.  
  233.     $params = new JParameter( $plugin->params );
  234.  
  235.     if ($params->get('showall') )
  236.     {
  237.         $link = JRoute::_( '&showall=1&limitstart=');
  238.         $row->toc .= '
  239.         <tr>
  240.             <td>
  241.                 <a href="'. $link .'" class="toclink">'
  242.                 . JText::_( 'All Pages' ) .
  243.                 '</a>
  244.             </td>
  245.         </tr>
  246.         ';
  247.     }
  248.     $row->toc .= '</table>';
  249. }
  250.  
  251. function plgContentCreateNavigation( &$row, $page, $n )
  252. {
  253.     $pnSpace = "";
  254.     if (JText::_( '<' ) || JText::_( '>' )) $pnSpace = " ";
  255.  
  256.     if ( $page < $n-1 )
  257.     {
  258.         $page_next = $page + 1;
  259.  
  260.         $link_next = JRoute::_( '&limitstart='. ( $page_next ) );
  261.         // Next >>
  262.         $next = '<a href="'. $link_next .'">' . JText::_( 'Next' ) . $pnSpace . JText::_( '>' ) . JText::_( '>' ) .'</a>';
  263.     }
  264.     else
  265.     {
  266.         $next = JText::_( 'Next' );
  267.     }
  268.  
  269.     if ( $page > 0 )
  270.     {
  271.         $page_prev = $page - 1 == 0 ? "" : $page - 1;
  272.  
  273.         $link_prev = JRoute::_(  '&limitstart='. ( $page_prev) );
  274.         // << Prev
  275.         $prev = '<a href="'. $link_prev .'">'. JText::_( '<' ) . JText::_( '<' ) . $pnSpace . JText::_( 'Prev' ) .'</a>';
  276.     }
  277.     else
  278.     {
  279.         $prev = JText::_( 'Prev' );
  280.     }
  281.  
  282.     $row->text .= '<div>' . $prev . ' - ' . $next .'</div>';
  283. }
  284.